/**********************************************************************
  The MIT License (MIT)
  Copyright (c) 2012 sunriseyuen

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
  THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ***********************************************************************/

#define _DEF_CCY_CODE
#define _ZZDEBUG
#define _PROJ_DC

#region Using directives

using System;
using System.Text;
using System.IO;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using System.Web;
using System.Web.UI;

using Muki.Framework;
using Muki.Framework.UI;
using Muki.Framework.Business;
using Muki.Framework.Util;
using Muki.UserDefine;
using Muki.Entity;
using Dot.StreamObject;

#endregion

namespace Muki.UserPanel
{

	public class UID02808BUI:BaseAction
	{
		public UID02808BUI()
		{
		}

		public override void OnRetrieve(string cDefined_Code)
		{
			if (!_Retrieve(cDefined_Code))
			{
				if (cDefined_Code=="")
				{
					_UID02808BV.Exceptions.Clear();
					if (!_Retrieve("MN"))
					{
						if (!_Retrieve("MP")){
							this.OnDefault();
						}
					}
				}
			}
		}

		private bool _Retrieve(string cDefined_Code)
		{
			VContexts _VContexts=new VContexts();

			_VContexts.setValue("UDEF_CODE",cDefined_Code);

				UID02808BE _Entity=_UID02808BV.Entity;

				if (cDefined_Code=="PICKUP") {
					Spliter _PK_Spliter      = new Spliter(_UID02808BV.ZZEventOpts);
					_PK_Spliter.Separator    = '|';
					_PK_Spliter.Separatorb   = '=';
					_PK_Spliter.DecodeBase64 = true;
					_PK_Spliter.Split();

							_Entity.PO_DT=_PK_Spliter["PO_DT"];
				}else if (cDefined_Code=="ACTIVETAB") {
					_UID02808BV.ZZLookup               = _UID02808BV.STATUS_DATA["UID02808B","lookup"];

					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["t1"]=_UID02808BV.STATUS_DATA["UID02808B","t1"];
					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["t2"]=_UID02808BV.STATUS_DATA["UID02808B","t2"];
					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["t3"]=_UID02808BV.STATUS_DATA["UID02808B","t3"];

					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["v1"]=_UID02808BV.STATUS_DATA["UID02808B","v1"];
					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["v2"]=_UID02808BV.STATUS_DATA["UID02808B","v2"];
					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["v3"]=_UID02808BV.STATUS_DATA["UID02808B","v3"];
					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["Restrict"]    =_UID02808BV.STATUS_DATA["UID02808B","Restrict"]    ;
					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["AbsolutePage"]=_UID02808BV.STATUS_DATA["UID02808B","AbsolutePage"];
					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["Condition"]   =_UID02808BV.STATUS_DATA["UID02808B","Condition"]   ;
					_UID02808BV.CellsPanel.VIEW_STATUS_DATA["ZZPageSize"]=_UID02808BV.STATUS_DATA["UID02808B","ZZPageSize"];

									_Entity.PO_NO=_UID02808BV.STATUS_DATA["UID02808A","PK_PO_NO"];
				}else{
					_VContexts.setValue("lookup",_UID02808BV.ZZLookup);

					_UID02808BV.STATUS_DATA["UID02808B","lookup"] = _UID02808BV.ZZLookup;
				}

								_Entity.PO_NO=_UID02808BV.STATUS_DATA["UID02808A","PK_PO_NO"];

				UID02808BE _NewEntity=_UID02808BM.Retrieves(_VContexts,_Entity);

				if (_NewEntity.DATA_STATUS_CODE=="Verified") {
					_UID02808BV.Entity             = _NewEntity;
					_UID02808BV.ZZVIEW_STATUS_CODE = _UID02808BV.ZZEventStatus;
					_UID02808BV.ZZVIEW_MODE_CODE = _UID02808BV.ZZEventMode;
				}
				_UID02808BV.Exceptions=_NewEntity.Exceptions;
				return _NewEntity.DATA_STATUS_CODE=="Verified";
		}

		public override void OnDefault()
		{
			UID02808BE _Entity=new UID02808BE();

						_Entity.PO_NO=_UID02808BV.STATUS_DATA["UID02808A","PK_PO_NO"];

			UID02808BE _NewEntity=_UID02808BM.Default(_Entity);

			if (_NewEntity.Exceptions.Count==0) {
				this.Trans.Commit();

				_UID02808BV.Entity             = _NewEntity;
				_UID02808BV.ZZVIEW_STATUS_CODE = _UID02808BV.ZZEventStatus;
				_UID02808BV.ZZVIEW_MODE_CODE = _UID02808BV.ZZEventMode;
			}
			_UID02808BV.Exceptions=_NewEntity.Exceptions;

		}

		public override void OnUpdate()
		{

			UID02808BE _NewEntity=_UID02808BM.Update(_UID02808BV.Entity);

			if (_NewEntity.Exceptions.Count==0){
				this.Trans.Commit();

				_UID02808BV.Entity             = _NewEntity;
				_UID02808BV.ZZVIEW_STATUS_CODE = _UID02808BV.ZZEventStatus;
				_UID02808BV.ZZVIEW_MODE_CODE = _UID02808BV.ZZEventMode;
			}
			_UID02808BV.Exceptions=_NewEntity.Exceptions;

		}		

		public override void OnAddNew()
		{

			UID02808BE _NewEntity=_UID02808BM.AddNew(_UID02808BV.Entity);

			foreach (LogisticException tmp in _NewEntity.Exceptions)
			{
				ZZTrace.Debug(ZFILE_NAME,tmp);
			}

			if (_NewEntity.Exceptions.Count==0) {
				this.Trans.Commit();

				_UID02808BV.Entity             = _NewEntity;
				_UID02808BV.ZZVIEW_STATUS_CODE = _UID02808BV.ZZEventStatus;
				_UID02808BV.ZZVIEW_MODE_CODE = _UID02808BV.ZZEventMode;
			}
			_UID02808BV.Exceptions=_NewEntity.Exceptions;

		}

		public override void OnChange(string cArg_Code)
		{

			if (cArg_Code!="") {
				_UID02808BV.ZZVIEW_STATUS_CODE = _UID02808BV.ZZEventStatus;
				_UID02808BV.ZZVIEW_MODE_CODE = _UID02808BV.ZZEventMode;
			}else{

				MessageInfo oMessageInfo  = new MessageInfo();
				oMessageInfo.DbName       = this.DbName;
				oMessageInfo.Trans        = this.Trans;
				oMessageInfo.ZZLOGON_LANG = this.ZZLOGON_LANG;
				oMessageInfo.ZZLOGON_SSD  = this.ZZLOGON_SSD;

				int _SUCCESS=0;
				int _FAILURE=0;
				if (_UID02808BV.ZZMODEL_DATA=="B") {

					_UID02808BV.ZZWxf.MoveFirst();
					while (!_UID02808BV.ZZWxf.EOF) {
						_UID02808BV.ZZWxf.Operation="P";
						_UID02808BV.ZZWxf.Reference="";

						VContexts _VContexts=new VContexts();

						_VContexts.setValue("UDEF_CODE","READ");

						bool Verified=false;
						UID02808BE _NewEntity=null;
						if (_UID02808BV.ZZWxf.PK_DATA!=""){

							Spliter _PK_Spliter      = new Spliter(_UID02808BV.ZZWxf.PK_DATA);
							_PK_Spliter.Separator    = '|';
							_PK_Spliter.Separatorb   = '=';
							_PK_Spliter.DecodeBase64 = true;
							_PK_Spliter.Split();

							UID02808BE _Entity=_UID02808BV.Entity;

									_Entity.PO_DT=_PK_Spliter["PO_DT"];

											if (_UID02808BV.STATUS_DATA["UID02808A","PK_PO_NO"]!="")
											{
												_Entity.PO_NO=_UID02808BV.STATUS_DATA["UID02808A","PK_PO_NO"];
											}

							_NewEntity=_UID02808BM.Retrieves(_VContexts,_Entity);

							if (_NewEntity.DATA_STATUS_CODE=="Verified") 
							{
								Verified=true;
								foreach (AttributeMapping _AttributeMapping in _UID02808BV.ZZWxf.Fields)
								{
									if (_AttributeMapping.STATUS_CODE.IndexOf("UPDATE")>=0) {
												if (_AttributeMapping.Name=="PORDTLM.ITEM_NO") {
														_NewEntity.ITEM_NO=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
												}
												if (_AttributeMapping.Name=="PORDTLM.PU_REQ_QTY") {
														_NewEntity.PU_REQ_QTY=_UID02808BV.ZZWxf.getDecimal(_AttributeMapping.Name);
												}
												if (_AttributeMapping.Name=="PORDTLM.PU_UNIT_PRICE") {
														_NewEntity.PU_UNIT_PRICE=_UID02808BV.ZZWxf.getDecimal(_AttributeMapping.Name);
												}
												if (_AttributeMapping.Name=="PORDTLM.PU_UOM_CODE") {
														_NewEntity.PU_UOM_CODE=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_REQ_DATE") {
														_NewEntity.PO_REQ_DATE=_UID02808BV.ZZWxf.getDateTime(_AttributeMapping.Name);
												}
												if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX3") {
														_NewEntity.TRANS_UDFX3=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
												}
												if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX4") {
														_NewEntity.TRANS_UDFX4=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_DT_RMKS") {
														_NewEntity.PO_DT_RMKS=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
												}
									}
								}
							}else{
								_NewEntity=_Entity;
							}
						}
						if (Verified)
						{
							foreach (LogisticException tmp in _NewEntity.Exceptions)
							{
								ZZTrace.Debug(ZFILE_NAME,tmp);
							}

							UID02808BE _NewEntity2=_UID02808BM.Update(_NewEntity);

							string cMsg="";
							foreach (LogisticException tmp in _NewEntity2.Exceptions)
							{
								cMsg=cMsg+oMessageInfo.Message("UID02808B",tmp)+"||";
							}

							if (_NewEntity2.Exceptions.Count==0)
							{
								UID02808BE _NewEntity3=_UID02808BM.Retrieves(_VContexts,_NewEntity2);

								foreach (LogisticException tmp in _NewEntity3.Exceptions)
								{
									ZZTrace.Debug(ZFILE_NAME,tmp);
								}

								if (_NewEntity3.DATA_STATUS_CODE=="Verified")
								{
									_SUCCESS++;
									_UID02808BV.ZZWxf.Operation="Y";
								}else{
									_UID02808BV.ZZWxf.Operation="R";
									_FAILURE++;
								}

								foreach (AttributeMapping _AttributeMapping in _UID02808BV.ZZWxf.Fields)
								{
												if (_AttributeMapping.Name=="PORDTLM.PO_NO") {
													_UID02808BV.ZZWxf["PORDTLM.PO_NO"]=_NewEntity3.PO_NO;
												}
												if (_AttributeMapping.Name=="PORDTLM.SERIAL_NO") {
													_UID02808BV.ZZWxf["PORDTLM.SERIAL_NO"]=_NewEntity3.SERIAL_NO;
												}
												if (_AttributeMapping.Name=="PORHDTM.ODTP_STATUS") {
													_UID02808BV.ZZWxf["PORHDTM.ODTP_STATUS"]=_NewEntity3.ODTP_STATUS;
												}
												if (_AttributeMapping.Name=="PORHDTM.VEN_CODE") {
													_UID02808BV.ZZWxf["PORHDTM.VEN_CODE"]=_NewEntity3.VEN_CODE;
												}
												if (_AttributeMapping.Name=="VENRTBM.VEN_NAME01") {
													_UID02808BV.ZZWxf["VENRTBM.VEN_NAME01"]=_NewEntity3.VEN_NAME01;
												}
												if (_AttributeMapping.Name=="PORDTLM.ITEM_NO") {
													_UID02808BV.ZZWxf["PORDTLM.ITEM_NO"]=_NewEntity3.ITEM_NO;
												}
												if (_AttributeMapping.Name=="PARTBLM.ITEM_NAME01") {
													_UID02808BV.ZZWxf["PARTBLM.ITEM_NAME01"]=_NewEntity3.ITEM_NAME01;
												}
												if (_AttributeMapping.Name=="PORDTLM.UOM_CODE") {
													_UID02808BV.ZZWxf["PORDTLM.UOM_CODE"]=_NewEntity3.UOM_CODE;
												}
												if (_AttributeMapping.Name=="PARTBLM.ITEM_NAME02") {
													_UID02808BV.ZZWxf["PARTBLM.ITEM_NAME02"]=_NewEntity3.ITEM_NAME02;
												}
												if (_AttributeMapping.Name=="PORDTLM.PU_REQ_QTY") {
													_UID02808BV.ZZWxf["PORDTLM.PU_REQ_QTY"]=_NewEntity3.PU_REQ_QTY;
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_REQ_QTY") {
													_UID02808BV.ZZWxf["PORDTLM.PO_REQ_QTY"]=_NewEntity3.PO_REQ_QTY;
												}
												if (_AttributeMapping.Name=="PORDTLM.UOM_XCHG") {
													_UID02808BV.ZZWxf["PORDTLM.UOM_XCHG"]=_NewEntity3.UOM_XCHG;
												}
												if (_AttributeMapping.Name=="PORDTLM.PU_UNIT_PRICE") {
													_UID02808BV.ZZWxf["PORDTLM.PU_UNIT_PRICE"]=_NewEntity3.PU_UNIT_PRICE;
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_UNIT_PRICE") {
													_UID02808BV.ZZWxf["PORDTLM.PO_UNIT_PRICE"]=_NewEntity3.PO_UNIT_PRICE;
												}
												if (_AttributeMapping.Name=="PORDTLM.PU_UOM_CODE") {
													_UID02808BV.ZZWxf["PORDTLM.PU_UOM_CODE"]=_NewEntity3.PU_UOM_CODE;
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_REQ_DATE") {
													_UID02808BV.ZZWxf["PORDTLM.PO_REQ_DATE"]=_NewEntity3.PO_REQ_DATE;
												}
												if (_AttributeMapping.Name=="PORHDTM.CCY_CODE") {
													_UID02808BV.ZZWxf["PORHDTM.CCY_CODE"]=_NewEntity3.CCY_CODE;
												}
												if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX3") {
													_UID02808BV.ZZWxf["PORDTLM.TRANS_UDFX3"]=_NewEntity3.TRANS_UDFX3;
												}
												if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX4") {
													_UID02808BV.ZZWxf["PORDTLM.TRANS_UDFX4"]=_NewEntity3.TRANS_UDFX4;
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_DT_RMKS") {
													_UID02808BV.ZZWxf["PORDTLM.PO_DT_RMKS"]=_NewEntity3.PO_DT_RMKS;
												}
								}
							}else{
								_FAILURE++;
								_UID02808BV.ZZWxf.Reference=cMsg;
								_UID02808BV.ZZWxf.Operation="F";

								foreach (AttributeMapping _AttributeMapping in _UID02808BV.ZZWxf.Fields)
								{
												if (_AttributeMapping.Name=="PORDTLM.PO_NO") {
													_UID02808BV.ZZWxf["PORDTLM.PO_NO"]=_NewEntity2.PO_NO;
												}
												if (_AttributeMapping.Name=="PORDTLM.SERIAL_NO") {
													_UID02808BV.ZZWxf["PORDTLM.SERIAL_NO"]=_NewEntity2.SERIAL_NO;
												}
												if (_AttributeMapping.Name=="PORHDTM.ODTP_STATUS") {
													_UID02808BV.ZZWxf["PORHDTM.ODTP_STATUS"]=_NewEntity2.ODTP_STATUS;
												}
												if (_AttributeMapping.Name=="PORHDTM.VEN_CODE") {
													_UID02808BV.ZZWxf["PORHDTM.VEN_CODE"]=_NewEntity2.VEN_CODE;
												}
												if (_AttributeMapping.Name=="VENRTBM.VEN_NAME01") {
													_UID02808BV.ZZWxf["VENRTBM.VEN_NAME01"]=_NewEntity2.VEN_NAME01;
												}
												if (_AttributeMapping.Name=="PORDTLM.ITEM_NO") {
													_UID02808BV.ZZWxf["PORDTLM.ITEM_NO"]=_NewEntity2.ITEM_NO;
												}
												if (_AttributeMapping.Name=="PARTBLM.ITEM_NAME01") {
													_UID02808BV.ZZWxf["PARTBLM.ITEM_NAME01"]=_NewEntity2.ITEM_NAME01;
												}
												if (_AttributeMapping.Name=="PORDTLM.UOM_CODE") {
													_UID02808BV.ZZWxf["PORDTLM.UOM_CODE"]=_NewEntity2.UOM_CODE;
												}
												if (_AttributeMapping.Name=="PARTBLM.ITEM_NAME02") {
													_UID02808BV.ZZWxf["PARTBLM.ITEM_NAME02"]=_NewEntity2.ITEM_NAME02;
												}
												if (_AttributeMapping.Name=="PORDTLM.PU_REQ_QTY") {
													_UID02808BV.ZZWxf["PORDTLM.PU_REQ_QTY"]=_NewEntity2.PU_REQ_QTY;
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_REQ_QTY") {
													_UID02808BV.ZZWxf["PORDTLM.PO_REQ_QTY"]=_NewEntity2.PO_REQ_QTY;
												}
												if (_AttributeMapping.Name=="PORDTLM.UOM_XCHG") {
													_UID02808BV.ZZWxf["PORDTLM.UOM_XCHG"]=_NewEntity2.UOM_XCHG;
												}
												if (_AttributeMapping.Name=="PORDTLM.PU_UNIT_PRICE") {
													_UID02808BV.ZZWxf["PORDTLM.PU_UNIT_PRICE"]=_NewEntity2.PU_UNIT_PRICE;
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_UNIT_PRICE") {
													_UID02808BV.ZZWxf["PORDTLM.PO_UNIT_PRICE"]=_NewEntity2.PO_UNIT_PRICE;
												}
												if (_AttributeMapping.Name=="PORDTLM.PU_UOM_CODE") {
													_UID02808BV.ZZWxf["PORDTLM.PU_UOM_CODE"]=_NewEntity2.PU_UOM_CODE;
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_REQ_DATE") {
													_UID02808BV.ZZWxf["PORDTLM.PO_REQ_DATE"]=_NewEntity2.PO_REQ_DATE;
												}
												if (_AttributeMapping.Name=="PORHDTM.CCY_CODE") {
													_UID02808BV.ZZWxf["PORHDTM.CCY_CODE"]=_NewEntity2.CCY_CODE;
												}
												if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX3") {
													_UID02808BV.ZZWxf["PORDTLM.TRANS_UDFX3"]=_NewEntity2.TRANS_UDFX3;
												}
												if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX4") {
													_UID02808BV.ZZWxf["PORDTLM.TRANS_UDFX4"]=_NewEntity2.TRANS_UDFX4;
												}
												if (_AttributeMapping.Name=="PORDTLM.PO_DT_RMKS") {
													_UID02808BV.ZZWxf["PORDTLM.PO_DT_RMKS"]=_NewEntity2.PO_DT_RMKS;
												}
								}
							}
							//}
					}else{
						if (_NewEntity==null)
						{
							_NewEntity=new UID02808BE();
						}

						foreach (AttributeMapping _AttributeMapping in _UID02808BV.ZZWxf.Fields)
						{
							if (_AttributeMapping.STATUS_CODE.IndexOf("UPDATE")>=0 || _AttributeMapping.STATUS_CODE.IndexOf("ADDNEW")>=0)
							{
										if (_AttributeMapping.Name=="PORDTLM.PO_NO") {
												_NewEntity.PO_NO=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.PO_DT") {
												_NewEntity.PO_DT=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.ITEM_NO") {
												_NewEntity.ITEM_NO=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.UOM_CODE") {
												_NewEntity.UOM_CODE=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.PU_REQ_QTY") {
												_NewEntity.PU_REQ_QTY=_UID02808BV.ZZWxf.getDecimal(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.PO_REQ_QTY") {
												_NewEntity.PO_REQ_QTY=_UID02808BV.ZZWxf.getDecimal(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.UOM_XCHG") {
												_NewEntity.UOM_XCHG=_UID02808BV.ZZWxf.getDecimal(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.PU_UNIT_PRICE") {
												_NewEntity.PU_UNIT_PRICE=_UID02808BV.ZZWxf.getDecimal(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.PO_UNIT_PRICE") {
												_NewEntity.PO_UNIT_PRICE=_UID02808BV.ZZWxf.getDecimal(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.PU_UOM_CODE") {
												_NewEntity.PU_UOM_CODE=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.PO_REQ_DATE") {
												_NewEntity.PO_REQ_DATE=_UID02808BV.ZZWxf.getDateTime(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX3") {
												_NewEntity.TRANS_UDFX3=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX4") {
												_NewEntity.TRANS_UDFX4=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
										}
										if (_AttributeMapping.Name=="PORDTLM.PO_DT_RMKS") {
												_NewEntity.PO_DT_RMKS=_UID02808BV.ZZWxf.getValue(_AttributeMapping.Name);
										}
							}
						}

										if (_UID02808BV.STATUS_DATA["UID02808A","PK_PO_NO"]!="")
										{
											_NewEntity.PO_NO=_UID02808BV.STATUS_DATA["UID02808A","PK_PO_NO"];
										}

						UID02808BE _NewEntity7=_UID02808BM.AddNew(_NewEntity);

						string cMsg="";
						foreach (LogisticException tmp in _NewEntity7.Exceptions)
						{
							cMsg=cMsg+oMessageInfo.Message("UID02808B",tmp)+"||";
						}

						if (_NewEntity7.Exceptions.Count==0) {
							UID02808BE _NewEntity8=_UID02808BM.Retrieves(_VContexts,_NewEntity7);
							cMsg="";
							foreach (LogisticException tmp in _NewEntity8.Exceptions)
							{
								cMsg=cMsg+oMessageInfo.Message("UID02808B",tmp)+"||";
								ZZTrace.Debug(ZFILE_NAME,tmp);
							}

							if (_NewEntity8.DATA_STATUS_CODE=="Verified") {
								_SUCCESS++;
								_UID02808BV.ZZWxf.PK_DATA=_NewEntity8.PK_DATA;
								_UID02808BV.ZZWxf.Operation="Y";
							}else{
								_UID02808BV.ZZWxf.Reference=cMsg;
								_UID02808BV.ZZWxf.Operation="R";
								_FAILURE++;
							}

							foreach (AttributeMapping _AttributeMapping in _UID02808BV.ZZWxf.Fields)
							{
											if (_AttributeMapping.Name=="PORDTLM.PO_NO") {
												_UID02808BV.ZZWxf["PORDTLM.PO_NO"]=_NewEntity8.PO_NO;
											}

											if (_AttributeMapping.Name=="PORDTLM.SERIAL_NO") {
												_UID02808BV.ZZWxf["PORDTLM.SERIAL_NO"]=_NewEntity8.SERIAL_NO;
											}

											if (_AttributeMapping.Name=="PORHDTM.ODTP_STATUS") {
												_UID02808BV.ZZWxf["PORHDTM.ODTP_STATUS"]=_NewEntity8.ODTP_STATUS;
											}

											if (_AttributeMapping.Name=="PORHDTM.VEN_CODE") {
												_UID02808BV.ZZWxf["PORHDTM.VEN_CODE"]=_NewEntity8.VEN_CODE;
											}

											if (_AttributeMapping.Name=="VENRTBM.VEN_NAME01") {
												_UID02808BV.ZZWxf["VENRTBM.VEN_NAME01"]=_NewEntity8.VEN_NAME01;
											}

											if (_AttributeMapping.Name=="PORDTLM.ITEM_NO") {
												_UID02808BV.ZZWxf["PORDTLM.ITEM_NO"]=_NewEntity8.ITEM_NO;
											}

											if (_AttributeMapping.Name=="PARTBLM.ITEM_NAME01") {
												_UID02808BV.ZZWxf["PARTBLM.ITEM_NAME01"]=_NewEntity8.ITEM_NAME01;
											}

											if (_AttributeMapping.Name=="PORDTLM.UOM_CODE") {
												_UID02808BV.ZZWxf["PORDTLM.UOM_CODE"]=_NewEntity8.UOM_CODE;
											}

											if (_AttributeMapping.Name=="PARTBLM.ITEM_NAME02") {
												_UID02808BV.ZZWxf["PARTBLM.ITEM_NAME02"]=_NewEntity8.ITEM_NAME02;
											}

											if (_AttributeMapping.Name=="PORDTLM.PU_REQ_QTY") {
												_UID02808BV.ZZWxf["PORDTLM.PU_REQ_QTY"]=_NewEntity8.PU_REQ_QTY;
											}

											if (_AttributeMapping.Name=="PORDTLM.PO_REQ_QTY") {
												_UID02808BV.ZZWxf["PORDTLM.PO_REQ_QTY"]=_NewEntity8.PO_REQ_QTY;
											}

											if (_AttributeMapping.Name=="PORDTLM.UOM_XCHG") {
												_UID02808BV.ZZWxf["PORDTLM.UOM_XCHG"]=_NewEntity8.UOM_XCHG;
											}

											if (_AttributeMapping.Name=="PORDTLM.PU_UNIT_PRICE") {
												_UID02808BV.ZZWxf["PORDTLM.PU_UNIT_PRICE"]=_NewEntity8.PU_UNIT_PRICE;
											}

											if (_AttributeMapping.Name=="PORDTLM.PO_UNIT_PRICE") {
												_UID02808BV.ZZWxf["PORDTLM.PO_UNIT_PRICE"]=_NewEntity8.PO_UNIT_PRICE;
											}

											if (_AttributeMapping.Name=="PORDTLM.PU_UOM_CODE") {
												_UID02808BV.ZZWxf["PORDTLM.PU_UOM_CODE"]=_NewEntity8.PU_UOM_CODE;
											}

											if (_AttributeMapping.Name=="PORDTLM.PO_REQ_DATE") {
												_UID02808BV.ZZWxf["PORDTLM.PO_REQ_DATE"]=_NewEntity8.PO_REQ_DATE;
											}

											if (_AttributeMapping.Name=="PORHDTM.CCY_CODE") {
												_UID02808BV.ZZWxf["PORHDTM.CCY_CODE"]=_NewEntity8.CCY_CODE;
											}

											if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX3") {
												_UID02808BV.ZZWxf["PORDTLM.TRANS_UDFX3"]=_NewEntity8.TRANS_UDFX3;
											}

											if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX4") {
												_UID02808BV.ZZWxf["PORDTLM.TRANS_UDFX4"]=_NewEntity8.TRANS_UDFX4;
											}

											if (_AttributeMapping.Name=="PORDTLM.PO_DT_RMKS") {
												_UID02808BV.ZZWxf["PORDTLM.PO_DT_RMKS"]=_NewEntity8.PO_DT_RMKS;
											}

							}

						}else{
							_FAILURE++;
							foreach (AttributeMapping _AttributeMapping in _UID02808BV.ZZWxf.Fields)
							{
											if (_AttributeMapping.Name=="PORDTLM.PO_NO") {
												_UID02808BV.ZZWxf["PORDTLM.PO_NO"]=_NewEntity7.PO_NO;
											}

											if (_AttributeMapping.Name=="PORDTLM.SERIAL_NO") {
												_UID02808BV.ZZWxf["PORDTLM.SERIAL_NO"]=_NewEntity7.SERIAL_NO;
											}

											if (_AttributeMapping.Name=="PORHDTM.ODTP_STATUS") {
												_UID02808BV.ZZWxf["PORHDTM.ODTP_STATUS"]=_NewEntity7.ODTP_STATUS;
											}

											if (_AttributeMapping.Name=="PORHDTM.VEN_CODE") {
												_UID02808BV.ZZWxf["PORHDTM.VEN_CODE"]=_NewEntity7.VEN_CODE;
											}

											if (_AttributeMapping.Name=="VENRTBM.VEN_NAME01") {
												_UID02808BV.ZZWxf["VENRTBM.VEN_NAME01"]=_NewEntity7.VEN_NAME01;
											}

											if (_AttributeMapping.Name=="PORDTLM.ITEM_NO") {
												_UID02808BV.ZZWxf["PORDTLM.ITEM_NO"]=_NewEntity7.ITEM_NO;
											}

											if (_AttributeMapping.Name=="PARTBLM.ITEM_NAME01") {
												_UID02808BV.ZZWxf["PARTBLM.ITEM_NAME01"]=_NewEntity7.ITEM_NAME01;
											}

											if (_AttributeMapping.Name=="PORDTLM.UOM_CODE") {
												_UID02808BV.ZZWxf["PORDTLM.UOM_CODE"]=_NewEntity7.UOM_CODE;
											}

											if (_AttributeMapping.Name=="PARTBLM.ITEM_NAME02") {
												_UID02808BV.ZZWxf["PARTBLM.ITEM_NAME02"]=_NewEntity7.ITEM_NAME02;
											}

											if (_AttributeMapping.Name=="PORDTLM.PU_REQ_QTY") {
												_UID02808BV.ZZWxf["PORDTLM.PU_REQ_QTY"]=_NewEntity7.PU_REQ_QTY;
											}

											if (_AttributeMapping.Name=="PORDTLM.PO_REQ_QTY") {
												_UID02808BV.ZZWxf["PORDTLM.PO_REQ_QTY"]=_NewEntity7.PO_REQ_QTY;
											}

											if (_AttributeMapping.Name=="PORDTLM.UOM_XCHG") {
												_UID02808BV.ZZWxf["PORDTLM.UOM_XCHG"]=_NewEntity7.UOM_XCHG;
											}

											if (_AttributeMapping.Name=="PORDTLM.PU_UNIT_PRICE") {
												_UID02808BV.ZZWxf["PORDTLM.PU_UNIT_PRICE"]=_NewEntity7.PU_UNIT_PRICE;
											}

											if (_AttributeMapping.Name=="PORDTLM.PO_UNIT_PRICE") {
												_UID02808BV.ZZWxf["PORDTLM.PO_UNIT_PRICE"]=_NewEntity7.PO_UNIT_PRICE;
											}

											if (_AttributeMapping.Name=="PORDTLM.PU_UOM_CODE") {
												_UID02808BV.ZZWxf["PORDTLM.PU_UOM_CODE"]=_NewEntity7.PU_UOM_CODE;
											}

											if (_AttributeMapping.Name=="PORDTLM.PO_REQ_DATE") {
												_UID02808BV.ZZWxf["PORDTLM.PO_REQ_DATE"]=_NewEntity7.PO_REQ_DATE;
											}

											if (_AttributeMapping.Name=="PORHDTM.CCY_CODE") {
												_UID02808BV.ZZWxf["PORHDTM.CCY_CODE"]=_NewEntity7.CCY_CODE;
											}

											if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX3") {
												_UID02808BV.ZZWxf["PORDTLM.TRANS_UDFX3"]=_NewEntity7.TRANS_UDFX3;
											}

											if (_AttributeMapping.Name=="PORDTLM.TRANS_UDFX4") {
												_UID02808BV.ZZWxf["PORDTLM.TRANS_UDFX4"]=_NewEntity7.TRANS_UDFX4;
											}

											if (_AttributeMapping.Name=="PORDTLM.PO_DT_RMKS") {
												_UID02808BV.ZZWxf["PORDTLM.PO_DT_RMKS"]=_NewEntity7.PO_DT_RMKS;
											}

							}
							_UID02808BV.ZZWxf.Reference=cMsg;
							_UID02808BV.ZZWxf.Operation="F";
						}

					}

					_UID02808BV.ZZWxf.MoveNext();
				}

				_UID02808BV.ZZWxf.Variable("SUCCESS",_SUCCESS);
				_UID02808BV.ZZWxf.Variable("FAILURE",_FAILURE);

				if (_FAILURE==0 && _SUCCESS>0) {
					this.Trans.Commit();
				}

			}
		}
	}

	public override void OnDelete()
	{
		int _SUCCESS=0;
		int _FAILURE=0;

		UID02808BE _NewEntity=new UID02808BE();

		if (_UID02808BV.lnk_MODE=="B") {
			_UID02808BV.ZZWxf.MoveFirst();
			while (!_UID02808BV.ZZWxf.EOF)
			{
				VContexts _VContexts=new VContexts();

				_VContexts.setValue("UDEF_CODE","");

				if (_UID02808BV.ZZWxf.PK_DATA!="" && _UID02808BV.ZZWxf.Operation=="f"  ) {

					Spliter _PK_Spliter      = new Spliter(_UID02808BV.ZZWxf.PK_DATA);
					_PK_Spliter.Separator    = '|';
					_PK_Spliter.Separatorb   = '=';
					_PK_Spliter.DecodeBase64 = true;
					_PK_Spliter.Split();

					UID02808BE _Entity=_UID02808BV.Entity;

							_Entity.PO_DT=_PK_Spliter["PO_DT"];

									_Entity.PO_NO=_UID02808BV.STATUS_DATA["UID02808A","PK_PO_NO"];

					_NewEntity=_UID02808BM.Delete(_UID02808BV.Entity);

					if (_NewEntity.Exceptions.Count==0) {
						_SUCCESS++;
					}else{
						_FAILURE++;
					}
				}
				_UID02808BV.ZZWxf.MoveNext();
			}

			if (_SUCCESS>0 && _FAILURE==0 ) {
				//this.Empty();
				this.OnRetrieve("");

				this.Trans.Commit();

			}

			if (_SUCCESS>=0 && _FAILURE==0 ) {
				_UID02808BV.ZZVIEW_STATUS_CODE = _UID02808BV.ZZEventStatus;
				_UID02808BV.ZZVIEW_MODE_CODE = _UID02808BV.ZZEventMode;
			}

		}else{
			_NewEntity=_UID02808BM.Delete(_UID02808BV.Entity);

			if (_NewEntity.Exceptions.Count==0) {

				this.OnRetrieve("");

				this.Trans.Commit();

				_UID02808BV.ZZVIEW_STATUS_CODE = _UID02808BV.ZZEventStatus;
				_UID02808BV.ZZVIEW_MODE_CODE = _UID02808BV.ZZEventMode;
			}
		}

		_UID02808BV.Exceptions=_NewEntity.Exceptions;

	}

	public override void OnUserDef(string cAction_Code,string cDefined_Code)
	{
		VContexts _VContexts=new VContexts();

		_VContexts.setValue("UDEF_CODE",cDefined_Code);
		_VContexts.setValue("Events",cAction_Code);
		_VContexts.setValue("STATUS_CODE",_UID02808BV.ZZVIEW_STATUS_CODE);
		_VContexts.setValue("Sender", "UID02808B");

		UID02808BE _NewEntity=_UID02808BM.UserDefine(_VContexts,_UID02808BV.Entity);

		if (_NewEntity.Exceptions.Count==0) {
			_UID02808BV.Entity             = _NewEntity;
			_UID02808BV.ZZVIEW_STATUS_CODE = _UID02808BV.ZZEventStatus;
			_UID02808BV.ZZVIEW_MODE_CODE   = _UID02808BV.ZZEventMode;

		}
		_UID02808BV.Exceptions=_NewEntity.Exceptions;
	}

	public override void Process()
	{
		try
		{
			checked
			{
				ZZTrace.Debug(ZFILE_NAME,"ZZEventStatus="+_UID02808BV.ZZEventStatus);
				ZZTrace.Debug(ZFILE_NAME,"ZZEventMode="+_UID02808BV.ZZEventMode);

				this.Trans                = new StreamContext(this.DbName);
				this.Trans.Writeable      = true;
				_UID02808BM.Trans       = this.Trans;
				_UID02808BM.ZZLOGON_SSD = _UID02808BV.ZZLOGON_SSD;
				_UID02808BM.Initialize();

				base.Process();

				ZZTrace.Error(ZFILE_NAME,"PK_XX");

			}
		}
		catch (LogisticException ErrMsg)
		{
			_UID02808BV.Exceptions.Add(ErrMsg);

			string cMessage = "Message=[" + ErrMsg.Message + "]" + "\nSource=[" + ErrMsg.Source + "]\nStackTrace=[" + ErrMsg.StackTrace + "]\nTargetSite=[" + ErrMsg.TargetSite + "]";

			ZZTrace.Error(ZFILE_NAME,cMessage);

			ZZTrace.Error(ZFILE_NAME,ErrMsg);

			try
			{
				this.Trans.RollBack();
			}
			catch (Exception Ex)
			{
				cMessage = "Message=[" + ErrMsg.Message + "]" + "\nSource=[" + ErrMsg.Source + "]\nStackTrace=[" + ErrMsg.StackTrace + "]\nTargetSite=[" + ErrMsg.TargetSite + "]";

				ZZTrace.Error(ZFILE_NAME,cMessage);

				ZZTrace.Error(ZFILE_NAME,Ex);
			}

		}
		catch (Exception e)
		{
			string cMessage2 = "Message=[" + e.Message + "]" + "\nSource=[" + e.Source + "]\nStackTrace=[" + e.StackTrace + "]\nTargetSite=[" + e.TargetSite + "]";

			ZZTrace.Error(ZFILE_NAME,cMessage2);

			_UID02808BV.Exceptions.Add(new LogisticException("UID02808B","SystemError",""));
			ZZTrace.Error(ZFILE_NAME,e);
			try
			{
				this.Trans.RollBack();
			}
			catch (Exception)
			{
			}
		}
		finally
		{
			this.Trans.Close();
		}
	}

	public override void Process_Aft()
	{
		if (_UID02808BV.ZZVIEW_MODE_CODE=="B" || _UID02808BV.ZZVIEW_MODE_CODE=="N"){
			_UID02808BM.DbName      = this.DbName;
			_UID02808BM.Trans       = this.ReadMode;
			_UID02808BM.ZZLOGON_SSD = _UID02808BV.ZZLOGON_SSD;

			VContexts _VContexts=new VContexts();

			_VContexts=_UID02808BV.CellsPanel.VIEW_STATUS_DATA;
			_VContexts.setValue("lookup",_UID02808BV.STATUS_DATA["UID02808B","lookup"]);

			UID02808BE _Entity=_UID02808BV.Entity;

						_Entity.PO_NO=_UID02808BV.STATUS_DATA["UID02808A","PK_PO_NO"];

			_UID02808BM.Search(_VContexts, _Entity);
			_UID02808BV.CellsPanel.VIEW_STATUS_DATA=_VContexts;

			_UID02808BV.STATUS_DATA["UID02808B","t1"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["t1"].ToString();
			_UID02808BV.STATUS_DATA["UID02808B","t2"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["t2"].ToString();
			_UID02808BV.STATUS_DATA["UID02808B","t3"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["t3"].ToString();

			_UID02808BV.STATUS_DATA["UID02808B","v1"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["v1"].ToString();
			_UID02808BV.STATUS_DATA["UID02808B","v2"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["v2"].ToString();
			_UID02808BV.STATUS_DATA["UID02808B","v3"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["v3"].ToString();
			_UID02808BV.STATUS_DATA["UID02808B","Restrict"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["Restrict"].ToString();
			_UID02808BV.STATUS_DATA["UID02808B","AbsolutePage"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["AbsolutePage"].ToString();
			_UID02808BV.STATUS_DATA["UID02808B","Condition"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["Condition"].ToString();
			_UID02808BV.STATUS_DATA["UID02808B","ZZPageSize"]=_UID02808BV.CellsPanel.VIEW_STATUS_DATA["ZZPageSize"].ToString();

		}
	}

	public override void OnInit(HttpContext  objHttpContext)		
	{

		_UID02808BM = new UID02808BM();
		_UID02808BV = new UID02808BV();

		_UID02808BV.OnInit(objHttpContext);

		this.DbName                = _UID02808BV.DbName;
		this.ZZEventArgs           = _UID02808BV.ZZEventArgs;
		this.ZZVIEW_STATUS_CODE    = _UID02808BV.ZZVIEW_STATUS_CODE;
		this.ZZVIEW_MODE_CODE      = _UID02808BV.ZZVIEW_MODE_CODE;
		this.ZZLOGON_LANG = _UID02808BV.ZZLOGON_LANG;
		this.ReadMode=_UID02808BV.Trans;

		_UID02808BM.ZZLOGON_ID   = _UID02808BV.ZZLOGON_ID;
		_UID02808BM.ZZLOGON_LANG = _UID02808BV.ZZLOGON_LANG;
		_UID02808BV.APP_PATH     = this.APP_PATH;
		_UID02808BV.setValue();
	}

	public override void Render(HtmlTextWriter objTextWriter)
	{
		try
		{
			if (_UID02808BV.ZZMODEL_DATA=="B")
			{
				_UID02808BV.ZZWxf.Variable("lnk_RW_NO",_UID02808BV.lnk_RW_NO);

				objTextWriter.WriteLine(_UID02808BV.ZZWxf.ToString());
			}else{
				_UID02808BV.getValue();
				_UID02808BV.Render(objTextWriter);
			}
		}
		finally
		{
			this.ReadMode.Close();
		}
	}

	const  string ZFILE_NAME   ="UID02808BC";
	const  string MUKI_EDITION ="MIN";

	private UID02808BM      _UID02808BM;
	private UID02808BV      _UID02808BV;

#region screen element
#endregion
}
}
